package com.coder520.sync_learning.demo.hookTest;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

public class CaptureThreadException {
    /**
     * 通过这个方法可以进行在线成发生了异常的时候进行出现回调信息
     * @param args
     */
    public static void main(String[] args){
        //设置回调接口
        Thread.setDefaultUncaughtExceptionHandler((t,e)->{
            System.out.println(t.getName()+"occur exception");
            e.printStackTrace();
        });

        final Thread thread=new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);

            }catch (InterruptedException e){
            }

            //这里会出现unchecked异常
            System.out.println(1/0);
        },"test-thread");

        thread.start();


    }
}
